#include <locale.h>
#include <time.h>
#include "parser/parser.h"
#include "utils/logger.h"

int main(int argc, char *argv[])
{
    if (argc < 2)
    {
        LOG_ERROR("Provide file, please");
        exit(EXIT_FAILURE);
    }
    const char *filename = argv[1];
    LOG_INFO("File to parse: '%s'", filename);

    FILE * pFile;
    char *locale = setlocale(LC_ALL, "");
    pFile = fopen (filename,"r");
    if (!pFile)
    {
        LOG_ERROR("Couldn't open '%s'", filename);
        exit(EXIT_FAILURE);
    }
    LOG_INFO("Starting parsing");
    clock_t clockStart = clock();
    const HtmlDocument *doc = parse(pFile);
    clock_t clockEnd = clock();
    LOG_INFO("Parsing finished. It took %f miliseconds", ((float)(clockEnd - clockStart))/CLOCKS_PER_SEC*1000.0);
    fclose (pFile);

    if (!doc)
    {
        LOG_ERROR("Error during parsing file '%s'", filename);
        exit(EXIT_FAILURE);
    }

    return 0;
}
